home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / mmailp.idb / usr / lib / Zmail / bin / sh-versions / showexternal.z / showexternal
Encoding:
Text File  |  1997-01-22  |  6.2 KB  |  268 lines

  1. :
  2. # Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
  3. # Permission to use, copy, modify, and distribute this material 
  4. # for any purpose and without fee is hereby granted, provided 
  5. # that the above copyright notice and this permission notice 
  6. # appear in all copies, and that the name of Bellcore not be 
  7. # used in advertising or publicity pertaining to this 
  8. # material without the specific, prior written permission 
  9. # of an authorized representative of Bellcore.  BELLCORE 
  10. # MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
  11. # OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
  12. # WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  13.  
  14. # Conversion from C shell to Bourne shell by Z-Code Software Corp.
  15. # Conversion Copyright (c) 1992 Z-Code Software Corp.
  16. # Permission to use, copy, modify, and distribute this material
  17. # for any purpose and without fee is hereby granted, provided
  18. # that the above copyright notice and this permission notice
  19. # appear in all copies, and that the name of Z-Code Software not
  20. # be used in advertising or publicity pertaining to this
  21. # material without the specific, prior written permission
  22. # of an authorized representative of Z-Code.  Z-CODE SOFTWARE
  23. # MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY
  24. # OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS",
  25. # WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  26.  
  27. # Brought into line with metamail 2.7 beta release Csh version
  28. #    Dave Shield    February 1994
  29.  
  30. if test -f /usr/lib/sendmail
  31. then
  32.     MAILCOMMAND=/usr/lib/sendmail
  33. else
  34.     MAILCOMMAND=/bin/mail
  35. fi
  36.  
  37. if test "$#" -lt 3
  38. then
  39.     echo "Usage: showexternal body-file access-type name [site [directory [mode]]]"
  40.     exit 1
  41. fi
  42.  
  43. if [ -z "$METAMAIL_TMPDIR" ]
  44. then
  45.     METAMAIL_TMPDIR=/tmp
  46. fi
  47.  
  48. bodyfile=$1
  49. atype=`echo $2 | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
  50. name=$3
  51.  
  52. site=$4
  53.  
  54. dir=$5
  55.  
  56. mode=$6
  57.  
  58. server=$7
  59.  
  60. if test -z "$server" -a $atype = "mail-server"
  61. then
  62.     server=${name}@${site}
  63.     echo WARNING -- old style mailserver syntax, using server $server
  64. fi
  65.  
  66. ctype=`grep -i content-type: $bodyfile | sed -e 's/............: //'`
  67. if test -z "$ctype"
  68. then ctype="text/plain"
  69. fi
  70. cenc=`grep -i content-transfer-encoding: $bodyfile | sed -e 's/.........................: //'`
  71. username=""
  72. pass=""
  73. TMPDIR=$METAMAIL_TMPDIR/XXXternal.$$
  74. trap 'cd $METAMAIL_TMPDIR ; rmdir "$TMPDIR" >/dev/null 2>&1' 1 2 3 15
  75. mkdir $TMPDIR
  76. PUSHED_DIR=`pwd`
  77. cd $TMPDIR
  78. NEWNAME="mm.ext.$$"
  79. NEEDSCONFIRMATION=1
  80.  
  81. case $atype in
  82.     anon-ftp)
  83.         echo "This mail message contains a POINTER (reference) to data that is "
  84.         echo not included in the message itself.  Rather, the data can be retrieved 
  85.         echo automatically using anonymous FTP to a site on the network. ;;
  86.         
  87.     ftp)
  88.         echo "This mail message contains a POINTER (reference) to data that is "
  89.         echo not included in the message itself.  Rather, the data can be retrieved 
  90.         echo automatically using the FTP protocol to a site on the network. ;;
  91.  
  92.     mail-server)
  93.         cat > $METAMAIL_TMPDIR/ext.junk.$$ <<!
  94. This mail message contains a POINTER (reference) to data that is not
  95. included in the message itself.  Rather, the data can be retrieved by
  96. sending a special mail message to a mail server on the network.
  97. However, doing this automatically is slightly dangerous, because
  98. someone might be using this mechanism to cause YOU to send obnoxious
  99. mail.  For that reason, the mail message that WOULD be sent is being
  100. shown to you first for your approval.
  101.  
  102. This is the message that will be sent if you choose to go ahead and
  103. retrieve the external data:
  104.  
  105. Subject: Automated Mail Server Request
  106. To: $server
  107.  
  108. !
  109.         sed -e 1,/^\$/d < $bodyfile >> $METAMAIL_TMPDIR/ext.junk.$$
  110.         more $METAMAIL_TMPDIR/ext.junk.$$
  111.         rm $METAMAIL_TMPDIR/ext.junk.$$ ;;
  112.  
  113.     *)
  114.         NEEDSCONFIRMATION=0 ;;
  115. esac
  116.  
  117. if test $NEEDSCONFIRMATION -ne 0
  118. then
  119.     echo ""
  120.     echo-n "Do you want to proceed with retrieving the external data? [y] "
  121.     read ANS
  122.     case "$ANS" in
  123.         [Nn]*)    cd $METAMAIL_TMPDIR
  124.             rm -rf $TMPDIR;
  125.             exit 0 ;;
  126.     esac
  127. fi
  128.  
  129. case "$atype" in
  130.     anon-ftp | ftp)
  131.         case "$atype" in
  132.         anon-ftp )
  133.             username=anonymous
  134.             pass=`whoami`@`hostname`
  135.             ;;
  136.         esac
  137.  
  138.         if test -z "$site"
  139.         then
  140.             echo-n "Site for ftp access: "
  141.             read site
  142.         fi
  143.         if test -z "$username"
  144.         then
  145.             echo-n "User name at site ${site}: "
  146.             read username
  147.         fi
  148.         if test -z "$pass"
  149.         then
  150.             echo-n "Password for user $username at site ${site}: "
  151.             stty -echo
  152.             read pass
  153.             stty echo
  154.             echo ""
  155.         fi
  156.         if test -z "$dir"
  157.         then
  158.             DIRCMD=""
  159.         else
  160.             DIRCMD="cd $dir"
  161.         fi
  162.         if test -z "$mode"
  163.         then
  164.             MODECMD=""
  165.         else
  166.             MODECMD="type $mode"
  167.         fi
  168.         echo OBTAINING MESSAGE BODY USING FTP
  169.         echo SITE: $site USER: $username
  170.         ${FTP:-ftp} -n <<!
  171. open $site
  172. user $username $pass
  173. $DIRCMD
  174. $MODECMD
  175. get $name $NEWNAME
  176. quit
  177. !
  178.         if test ! -r "$NEWNAME"
  179.         then
  180.             echo FTP failed.
  181.             cd $METAMAIL_TMPDIR
  182.             rm -rf $TMPDIR
  183.             exit 1
  184.         fi
  185.         ;;
  186.  
  187.     afs|local-file)
  188.         if test ! -r $name
  189.         then
  190.             echo local file not found
  191.             cd $METAMAIL_TMPDIR
  192.             rm -rf $TMPDIR
  193.             exit 1
  194.         fi
  195.         NEWNAME=$name
  196.         echo GETTING BODY FROM FILE NAMED: $NEWNAME ;;
  197.  
  198.     mail-server)
  199.         if test -z "$bodyfile"
  200.         then
  201.             echo mail-server access-type requires a body file
  202.             cd $METAMAIL_TMPDIR
  203.             rm -rf $TMPDIR
  204.             exit 1
  205.         fi
  206.         echo Subject: Automated Mail Server Request > $NEWNAME
  207.         echo To: $server >> $NEWNAME
  208.         echo "" >> $NEWNAME
  209.         sed -e 1,/^\$/d < $bodyfile >> $NEWNAME
  210.         $MAILCOMMAND -t < $NEWNAME
  211.         if test $? -ne 0
  212.         then
  213.             echo sendmail failed
  214.             cd $METAMAIL_TMPDIR
  215.             rm -rf $TMPDIR
  216.             exit 1
  217.         fi
  218.         cd $METAMAIL_TMPDIR
  219.         rm -rf $TMPDIR
  220.         echo Your $ctype data has been requested from a mail server.
  221.         exit 0 ;;
  222.     *)
  223.         echo UNRECOGNIZED ACCESS-TYPE
  224.         cd $METAMAIL_TMPDIR
  225.         rm -rf $TMPDIR
  226.         exit 1 ;;
  227. esac
  228.  
  229. if test "$cenc" = base64
  230. then
  231.     mimencode -u -b < $NEWNAME > OUT
  232.     mv OUT $NEWNAME
  233. elif test "$cenc" = quoted-printable
  234. then
  235.     mimencode -u -q < $NEWNAME > OUT
  236.     mv OUT $NEWNAME
  237. fi
  238.  
  239. cd $PUSHED_DIR
  240. case "$atype" in
  241.     local-file ) metamail -b -p -c $ctype $NEWNAME ;;
  242.     * ) metamail -b -p -c "$ctype" $TMPDIR/$NEWNAME ;;
  243. esac
  244.  
  245. if test $? -ne 0
  246. then
  247.     echo metamail failed
  248.     cd $METAMAIL_TMPDIR
  249.     rm -rf $TMPDIR
  250.     exit 1
  251. fi
  252.  
  253. if test ! "$NEWNAME" = "$name"
  254. then
  255.     echo ""
  256.     echo The data just displayed is stored in the file $TMPDIR/$NEWNAME
  257.     echo "Do you want to delete it?"
  258.     rm -i $TMPDIR/$NEWNAME
  259. fi
  260.  
  261. if test ! -r ${TMPDIR}/${NEWNAME}
  262. then
  263.     cd /
  264.     cd $METAMAIL_TMPDIR
  265.     rmdir $TMPDIR
  266. fi
  267.